package asava.utils;

/**
 * @author Tim Richter
 */
public enum Operator {
    INCR(12, "++"),
    DECR(12, "--"),
    DELETE(12, "delete"),
    PLUS(12, "+"),
    MIN(12, "-"),
    BITNOT(12, "~"),
    NOT(12, "!"),
    MUL(11, "*"),
    DIV(11, "/"),
    MOD(11, "%"),
    ADD(10, "+"),
    SUB(10, "-"),
    LSH(9, "<<"),
    RSH(9, ">>"),
    URSH(9, ">>>"),
    LT(8, "<"),
    GT(8, ">"),
    LE(8, "<="),
    GE(8, ">="),
    AS(8, "as"),
    IN(8, "in"),
    INSTANCEOF(8, "instanceof"),
    IS(8, "is"),
    EQ(7, "=="),
    NE(7, "!="),
    STREQ(7, "==="),
    STRNE(7, "!=="),
    BITAND(6, "&"),
    BITXOR(5, "^"),
    BITOR(4, "|"),
    AND(3, "&&"),
    OR(2, "||"),
    ASSIGN(1, true, "="),
    MULASSIGN(1, true, "*="),
    DIVASSIGN(1, true, "/="),
    MODASSIGN(1, true, "%="),
    ADDASSIGN(1, true, "+="),
    SUBASSIGN(1, true, "-="),
    LSHASSIGN(1, true, "<<="),
    RSHASSIGN(1, true, ">>="),
    URSHASSIGN(1, true, ">>>="),
    BITANDASSIGN(1, true, "&="),
    BITXORASSIGN(1, true, "^="),
    BITORASSIGN(1, true, "|="),
    NONE(0, "");

    public final int precedence;
    public final boolean isLeftAssociative;
    public final String value;

    private Operator(final int precedence,
                     final String value) {
        this(precedence, false, value);
    }

    private Operator(final int precedence,
                     final boolean isLeftAssociative,
                     final String value) {
        this.precedence = precedence;
        this.isLeftAssociative = isLeftAssociative;
        this.value = value;
    }

    @Override
    public String toString() {
        return value;
    }
}
